<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <!-- 主表单区域 -->
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="8" >
            <a-form-model-item label="时间" :labelCol="{ span: 6 }" :wrapperCol="{ span: 18 }" prop="date">
              <a-input v-model="model.date" placeholder="请输入时间" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8" >
            <a-form-model-item label="总分" :labelCol="{ span: 6 }" :wrapperCol="{ span: 18 }" prop="totalScore">
              <a-input-number v-model="model.totalScore" placeholder="" style="width: 100%" :disabled="true"/>
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="8" >
            <a-form-model-item label="学院" :labelCol="{ span: 6 }" :wrapperCol="{ span: 18 }" prop="orgId">
              <a-select  :disabled="disabled" placeholder="请选择" v-model="model.orgId" @change="queryMemberList" >
                <a-select-option v-for="(item, key) in this.selectedDate" :key="key" :value="item.value" >
                  <span style="display: inline-block;width: 100%" :title=" item.text || item.label ">
                    {{ item.text || item.label }}
                  </span>
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col :span="8" >
            <a-form-model-item label="学生数" :labelCol="{ span: 6 }" :wrapperCol="{ span: 18 }" prop="studentNum">
              <a-input-number v-model="model.studentNum" placeholder="请输入学生数" style="width: 100%" @blur="getTotalScore"/>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
      <!-- 子表单区域 -->
    <member-list ref="memberListRef" v-model="memberListTable.dataSource" :project-info="model" :disabled="formDisabled" :loading="memberListTable.loading"></member-list>
  </a-spin>
</template>

<script>

import { getAction } from '@/api/manage'
import MemberList from '@views/gfxy/common/memberList'
import GYearPicker from '@views/gfxy/common/GYearPicker'
import { GfxyMemberListMixin } from '@/mixins/GfxyMemberListMixin'

  export default {
    name: 'XssForm',
    mixins: [GfxyMemberListMixin],
    components: {
      MemberList,GYearPicker

    },
    data() {
      return {
        selectedDate:[
          {value:'301', text:'智能制造学院'},
          {value:'302', text:'人工智能学院'},
          {value:'303', text:'汽车工程学院'},
          {value:'304', text:'机械工程学院'},
          {value:'305', text:'电子信息学院'},
          {value:'306', text:'计算机与软件学院'},
          {value:'307', text:'化学工程学院'},
          {value:'308', text:'建筑工程学院'},
          {value:'309', text:'经济管理学院'},
          {value:'310', text:'艺术与设计学院'},
        ],

        validatorRules: {
          date: [
            { required: true, message: '请输入时间!'},
          ],
          studentNum: [
            { required: true, message: '请输入学生数!'},
          ],
          orgId: [
            { required: true, message: '请选择分院!'},
          ],
        },
        url: {
          add: "/items/xss/add",
          edit: "/items/xss/edit",
          queryById: "/items/xss/queryById",
          getTotalScore: "/items/xss/getTotalScore",
          memberList: {
            list: "/items/xss/queryMemberListByMainId"
          },
          getMemberList:"/items/xss/getMemberListByOrgId"
        }
      }
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      },
      itemValue:{
        type: Number,
        required: true,
      },
      date:{
        type: String,
        required: true,
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
    },
    methods: {
      getTotalScore(){
        if(this.model.studentNum != undefined ){
          this.confirmLoading = true;
          getAction(this.url.getTotalScore,{'studentNum': this.model.studentNum}).then((res) => {
            if (res.success) {
              this.model.totalScore = res.result;
              this.$nextTick(()=>{
                this.$refs.memberListRef.getScore();
              })
            }
            if(res.code===510){
              this.$message.warning(res.message)
            }

          }).finally(()=>{
              this.confirmLoading = false;
          })
        }
      },
      queryMemberList(){
        // this.confirmLoading = true;

        this.confirmLoading = true;
        this.$nextTick(()=>{
          this.$refs.memberListRef.initMemberList(this.model.orgId);
        })
        getAction(this.url.getMemberList,{'orgId': this.model.orgId})
          .then((res) =>{
            if (res.success) {
              console.log(res.result)
              this.memberListTable.dataSource = res.result;
              console.log(this.memberListTable.dataSource)
            }
            if(res.code===510){
              this.$message.warning(res.message)
            }
          }).finally(()=>{
          this.confirmLoading = false;
        })
      }
    }
  }
</script>

<style scoped>
</style>